home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / contrib / phrmp.bst < prev    next >
Lisp/Scheme  |  1992-07-19  |  67KB  |  2,151 lines

  1. % BibTeX styles for various physics journals (27-Feb-1990).
  2. % This file, physics.btx, is based on the file btxbst.doc.
  3.     % Please notify Charles Karney (Karney@Princeton.EDU)
  4.     % of any bugs, improvements, etc.
  5. % Run this file through cpp to get specific versions.  I have written
  6. % a version of cpp within Emacs.  To access it put
  7. %    (autoload 'cpp "tex$bibtex:cpp"        ; Use cpp for BibTeX styles
  8. %          "C preprocessor"
  9. %          t)
  10. % into your .emacs file.  Read in this file with
  11. %    emacs tex$bibtex:physics.btx
  12. % and run cpp with e.g.,
  13. %    M-x cpp <ret> aip <ret>
  14. % Save the resulting file to tex$latex:aip.bst.
  15. % To accomodate the variations we need (in addition to the definitions below)
  16. %    ATIT_SUPPRESS:    do not include the titles of journal articles
  17. %    NAME_INVERT:    put the initials last
  18. %    NAME_UPPER:    convert names to all caps.
  19. %    MONTH_SUPPRESS:    do not include months in journal articles
  20. %    PAREN_DATE:    dates go in parens in journal articles
  21. %    DATE_FIRST:    dates go before page numbers
  22. %    VOLUME_SPACE:    volume set off with space (not colon)
  23. %    NUM_SUPPRESS:    do not include numbers in journal articles
  24. %    BOLD_VOL:    volume numbers in bold face in journal articles
  25. %    BRACKET_NOTE:    notes in brackets
  26. %    PAGE_START_J:    include only starting page for journal articles
  27. %    PAGE_START_O:    include only starting page for other entries
  28. %    PAGE_ABBREV:    abbreviate page to p. and pages to pp.
  29. %    PHYSICS_JOUR:    include abbreviations for Physics journals
  30. %    COMMA_DELIMIT:    use comma (instead of period) to divide a citation
  31. %    NOTE_SUPPRESS:    suppress the note
  32. %    MAX_NAMES:    max number of authors before using et al (0 = infinity)
  33. %    MIN_NAMES:    number of authors to list with et al.
  34. %    EDIT_VAR:    use "edited by ..." instead of "..., editors"
  35. %    RMP_LABELS:    create 1-style labels
  36. %    KEY_CITE:    use key as label
  37. %    NAMED_REFS:    use (Smith, 1988) style of citations
  38. %    CSC_NAMES:    names set in caps and small caps
  39. %    JOUR_DEEMPH:    don't emphasize journal name
  40. %    ETAL_EMPH:    emphasize et al.
  41. %    ALT_INCOLL    alternate ordering of fields in incollections
  42. % These are all boolean (0 or 1) except for MAX_NAMES and MIN_NAMES.
  43. % These need to satisfy 0 <= MIN_NAMES <= MAX_NAMES.
  44. % The rule here is that if all these are defined to be zero, we revert to
  45. % the standard styles.  For that reason we initialize them all to 0.
  46. % These are the original macros
  47.     % For Reviews of Modern Physics, 
  48. % except first name not inverted yet and order of fields not hacked
  49. % This is the start of btxbst.doc
  50. % BibTeX `plain' family
  51.     % version 0.99b for BibTeX versions 0.99a or later, LaTeX version 2.09.
  52.     % Copyright (C) 1985, all rights reserved.
  53.     % Copying of this file is authorized only if either
  54.     % (1) you make absolutely no changes to your copy, including name, or
  55.     % (2) if you do make changes, you name it something other than
  56.     % btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
  57.     % This restriction helps ensure that all standard styles are identical.
  58.     % The file btxbst.doc has the documentation for this style.
  59. % Please notify Oren Patashnik (PATASHNIK@SCORE.STANFORD.EDU) of any bugs in
  60. % these standard styles or in this documentation file.
  61. %
  62. % This is file btxbxt.doc; it helps document bibliography styles,
  63. % and is also a template file that you can use to make
  64. % several different style files, if you have access to a C preprocessor.
  65. % For example, the standard styles were made by doing something like
  66. %    cpp -P -DPLAIN btxbst.doc plain.txt
  67. %    cpp -P -DUNSRT btxbst.doc unsrt.txt
  68. %    cpp -P -DALPHA btxbst.doc alpha.txt
  69. %    cpp -P -DABBRV btxbst.doc abbrv.txt
  70. % and then renaming after removing unwanted comments and blank lines.
  71. % If you don't have access,
  72. % you can edit this file by hand to imitate the preprocessor,
  73. % with the following explanation of the C preprocessor constructs used here.
  74. %
  75. % The output of the preprocessor is the same as the input, except that certain
  76. % lines will be excluded (and some blank lines will be added).  The sequence
  77. %    #if VAR
  78. %        lines to be included when VAR is not zero
  79. %    #else
  80. %        lines to be included when VAR is zero
  81. %    #endif
  82. % (with the #-signs appearing in column 1) means that one set or the other of
  83. % the lines are to be included depending on the value of VAR.
  84. % The #else part is optional.  Comments can be added after #else and #endif.
  85. % Variables can be set by
  86. %    #define VAR value
  87. % and one can also use #ifdef VAR to see if VAR has any value, and #ifndef
  88. % to see if it has none.
  89. % Another #if form used in this file is #if !VAR, which includes the lines
  90. % after the #if only if VAR is zero.
  91. %
  92. % Convention: Use all uppercase identifiers for these preprocessor variables
  93. % so you can spot them easily
  94. %
  95. % The command line to the preprocessor should define one of PLAIN, UNSRT, ALPHA
  96. % or ABBRV (though PLAIN will be used by default if none is given),
  97. % and the following lines will set various boolean variables to control the
  98. % various lines that are chosen from the rest of the file.
  99. % Each boolean variable should be set true (1) or false (0) in each style.
  100. % Here are the current variables, and their meanings:
  101. %    1:    an alphabetic label is used (if false then a numeric
  102. %                label is used)
  103. %    1:        the entries should be sorted by label (if nonnumeric)
  104. %                and other info, like authors (if false, then
  105. %                entries remain in order of occurrence)
  106. %    0:    the authors, editors, etc., get the full names as
  107. %                given in the bibliography file (if false, the first
  108. %                names become initials)
  109. %    1:    titles of non-"books" (e.g., articles) should be
  110. %                converted to lower-case, except the first letter or
  111. %                first letter after a colon
  112. %                (if false then they appear as in the database)
  113. %    0:    months are spelled out in full (if false, then
  114. %                they're abbreviated)
  115. %    0:    macro journal names are spelled out in full
  116. %                (if false then they are abbreviated, currently
  117. %                as they appear in ACM publications)
  118. %#        define PLAIN 1
  119. %
  120. %   Entry formatting: Similar to that recommended by Mary-Claire van Leunen
  121. %    in "A Handbook for Scholars".  Book-like titles are italicized
  122. %    (emphasized) and non-book titles are converted to sentence
  123. %    capitilization (and not enclosed in quotes).
  124. %    This file outputs a \newblock between major blocks of an entry
  125. %    (the name \newblock is analogous to the names \newline and \newpage)
  126. %    so that the user can obtain an "open" format, which has a line break
  127. %    before each block and lines after the first are indented within blocks,
  128. %    by giving the optional \documentstyle argument `openbib';
  129. %    The default is the "closed" format---blocks runs together.
  130. %
  131. %   Citation alphabetic label format:
  132. %        [Knu73] for single author (or editor or key)
  133. %        [AHU83] (first letters of last names) for multiple authors
  134. %
  135. %   Citation label numberic format:
  136. %        [number]
  137. %
  138. %   Reference list ordering for sorted, alphabetic lables:
  139. %        alphabetical by citation label, then by author(s) or whatever
  140. %        passes for author in the absence of one, then by year,
  141. %        then title
  142. %
  143. %   Reference list ordering for sorted, numeric lables:
  144. %        alphabetical by author(s) or whatever passes
  145. %        for author in the absence of one, then by year, then title
  146. %
  147. %   Reference list ordering for unsorted:
  148. %        by the order cited in the text
  149. %
  150. %   History
  151. %   12/16/84    (HWT)    Original `plain' version, by Howard Trickey.
  152. %   12/23/84    (LL)    Some comments made by Leslie Lamport.
  153. %    2/16/85    (OP)    Changes based on LL's comments, Oren Patashnik.
  154. %    2/17/85    (HWT)    Template file and other standard styles made.
  155. %    3/28/85    (OP)    First release, version 0.98b for BibTeX 0.98f.
  156. %    5/ 9/85    (OP)    Version 0.98c for BibTeX 0.98i:
  157. %            fixed Theoretical Computer Science macro name;
  158. %            fixed the format.vol.num.pages function.
  159. %    1/24/88    (OP)    Version 0.99a for BibTeX 0.99a, main changes:
  160. %            assignment operator (:=) arguments reversed;
  161. %            the preamble$ function outputs the database PREAMBLE;
  162. %            entry.max$ and global.max$ (built-in) variables replace
  163. %            entry.string.max and global.string.max functions;
  164. %            alphabetizing by year then title, not just title;
  165. %            many unnecessary ties removed; \it ==> \em;
  166. %            the `alpha' style uses a superscripted `+' instead of a
  167. %            `*' for unnamed names in constructing the label;
  168. %            the `abbrv' style now uses "Mar." and "Sept.";
  169. %            the functions calc.label and presort now look at just
  170. %            the fields they're supposed to;
  171. %            BOOKLET, MASTERSTHESIS, TECHREPORT use nonbook titles;
  172. %            INBOOK and INCOLLECTION take an optional type (e.g.
  173. %            type = "Section"), overriding the default "chapter";
  174. %            BOOK, INBOOK, INCOLLECTION, and PROCEEDINGS now allow
  175. %            either volume or number, not just volume;
  176. %            INCOLLECTION now allows an edition and series field;
  177. %            PROCEEDINGS and INPROCEEDINGS now use the address field
  178. %            to tell where a conference was held;
  179. %            INPROCEEDINGS and PROCEEDINGS now allow either volume
  180. %            or number, and also a series field;
  181. %            MASTERSTHESIS and PHDTHESIS accept types other than
  182. %            "Master's thesis" and "PhD thesis";
  183. %            UNPUBLISHED now outputs, in one block, note then date;
  184. %            MANUAL now prints out the organization in
  185. %            the first block if the author field is empty;
  186. %            MISC can't be empty---it requires some optional field.
  187. %    3/23/88    (OP)    Version 0.99b for BibTeX 0.99c---changed the three
  188. %            erroneous occurrences of `cite ' to `cite$ '; this
  189. %            change didn't affect the four standard styles, so the
  190. %            0.99a versions of those styles are still current.
  191. %
  192. % The ENTRY declaration
  193. %   Like Scribe's (according to pages 231-2 of the April '84 edition),
  194. %   but no fullauthor or editors fields because BibTeX does name handling.
  195. %   The annote field is commented out here because this family doesn't
  196. %   include an annotated bibliography style.  And in addition to the fields
  197. %   listed here, BibTeX has a built-in crossref field, explained later.
  198. ENTRY
  199. % Fields:
  200.   { address
  201. %        Usually the address of a publisher or other type of organization.
  202. %        Put information in this field only if it helps the reader find the
  203. %        thing---for example you should omit the address of a major
  204. %        publisher entirely.  For a PROCEEDINGS or an INPROCEEDINGS,
  205. %        however, it's the address of the conference; for those two entry
  206. %        types, include the publisher's or organization's address, if
  207. %        necessary, in the publisher or organization field.
  208. %    annote
  209. %        Long annotation---for annotated bibliographies (begins sentence).
  210.     author
  211. %        Name(s) of author(s), in BibTeX name format.
  212.     booktitle
  213. %        Book title when the thing being referenced isn't the whole book.
  214. %        For book entries, the title field should be used instead.
  215.     chapter
  216. %        Chapter (or section or whatever) number.
  217.     edition
  218. %        Edition of a book---should be an ordinal (e.g., "Second").
  219.     editor
  220. %        Name(s) of editor(s), in BibTeX name format.
  221. %        If there is also an author field, then the editor field should be
  222. %        for the book or collection that the work appears in.
  223.     howpublished
  224. %         How something strange has been published (begins sentence).
  225.     institution
  226. %        Sponsoring institution of a technical report.
  227.     journal
  228. %        Journal name (macros are provided for many).
  229.     key
  230. %        Alphabetizing, labeling, and cross-referencing key
  231. %        (needed when an entry has no author or editor).
  232.     month
  233. %        Month (macros are provided).
  234.     note
  235. %        To help the reader find a reference (begins sentence).
  236.     number
  237. %        Number of a journal or technical report, or of a work in a series.
  238.     organization
  239. %        Organization sponsoring a conference (or publishing a manual); if
  240. %        the editor (or author) is empty, and if the organization produces
  241. %        an awkward label or cross reference, you should put appropriately
  242. %        condensed organization information in the key field as well.
  243.     pages
  244. %        Page number or numbers (use `--' to separate a range, use `+'
  245. %        to indicate pages following that don't form a simple range).
  246.     publisher
  247. %        Publisher name.
  248.     school
  249. %        School name (for theses).
  250.     series
  251. %        The name of a series or set of books.
  252. %        An individual book will will also have it's own title.
  253.     title
  254. %        The title of the thing you're referred to.
  255.     type
  256. %        Type of a Techreport (e.g., "Research Note") to be used instead of
  257. %        the default "Technical Report"; or, similarly, the type of a
  258. %        thesis; or of a part of a book.
  259.     volume
  260. %        The volume number of a journal or multivolume work.
  261.     year
  262. %        The year should contain only numerals (technically, it should end
  263. %        with four numerals, after purification; doesn't a begin sentence).
  264.   }
  265. % There are no integer entry variables
  266.   {}
  267. % These string entry variables are used to form the citation label.
  268. % In a storage pinch, sort.label can be easily computed on the fly.
  269.   { label extra.label sort.label }
  270. % Each entry function starts by calling output.bibitem, to write the
  271. % \bibitem and its arguments to the .BBL file.  Then the various fields
  272. % are formatted and printed by output or output.check.  Those functions
  273. % handle the writing of separators (commas, periods, \newblock's),
  274. % taking care not to do so when they are passed a null string.
  275. % Finally, fin.entry is called to add the final period and finish the
  276. % entry.
  277. %
  278. % A bibliographic reference is formatted into a number of `blocks':
  279. % in the open format, a block begins on a new line and subsequent
  280. % lines of the block are indented.  A block may contain more than
  281. % one sentence (well, not a grammatical sentence, but something to
  282. % be ended with a sentence ending period).  The entry functions should
  283. % call new.block whenever a block other than the first is about to be
  284. % started.  They should call new.sentence whenever a new sentence is
  285. % to be started.  The output functions will ensure that if two
  286. % new.sentence's occur without any non-null string being output between
  287. % them then there won't be two periods output.  Similarly for two
  288. % successive new.block's.
  289. %
  290. % The output routines don't write their argument immediately.
  291. % Instead, by convention, that argument is saved on the stack to be
  292. % output next time (when we'll know what separator needs to come
  293. % after it).  Meanwhile, the output routine has to pop the pending
  294. % output off the stack, append any needed separator, and write it.
  295. %
  296. % To tell which separator is needed, we maintain an output.state.
  297. % It will be one of these values:
  298. %    before.all        just after the \bibitem
  299. %    mid.sentence        in the middle of a sentence: comma needed
  300. %                    if more sentence is output
  301. %    after.sentence        just after a sentence: period needed
  302. %    after.block        just after a block (and sentence):
  303. %                    period and \newblock needed.
  304. % Note: These styles don't use after.sentence
  305. %
  306. % VAR: output.state : INTEGER        -- state variable for output
  307. %
  308. % The output.nonnull function saves its argument (assumed to be nonnull)
  309. % on the stack, and writes the old saved value followed by any needed
  310. % separator.  The ordering of the tests is decreasing frequency of
  311. % occurrence.
  312. %
  313. % output.nonnull(s) ==
  314. %  BEGIN
  315. %    s := argument on stack
  316. %    if output.state = mid.sentence then
  317. %        write$(pop() * ", ")
  318. %          -- "pop" isn't a function: just use stack top
  319. %    else
  320. %        if output.state = after.block then
  321. %        write$(add.period$(pop()))
  322. %        newline$
  323. %        write$("\newblock ")
  324. %        else
  325. %        if output.state = before.all then
  326. %            write$(pop())
  327. %        else        -- output.state should be after.sentence
  328. %            write$(add.period$(pop()) * " ")
  329. %        fi
  330. %        fi
  331. %        output.state := mid.sentence
  332. %    fi
  333. %    push s on stack
  334. %  END
  335. %
  336. % The output function calls output.nonnull if its argument is non-empty;
  337. % its argument may be a missing field (thus, not necessarily a string)
  338. %
  339. % output(s) ==
  340. %  BEGIN
  341. %    if not empty$(s) then output.nonnull(s)
  342. %    fi
  343. %  END
  344. %
  345. % The output.check function is the same as the output function except that, if
  346. % necessary, output.check warns the user that the t field shouldn't be empty
  347. % (this is because it probably won't be a good reference without the field;
  348. % the entry functions try to make the formatting look reasonable even when
  349. % such fields are empty).
  350. %
  351. % output.check(s,t) ==
  352. %  BEGIN
  353. %    if empty$(s) then
  354. %        warning$("empty " * t * " in " * cite$)
  355. %    else output.nonnull(s)
  356. %    fi
  357. %  END
  358. %
  359. % The output.bibitem function writes the \bibitem for the current entry
  360. % (the label should already have been set up), and sets up the separator
  361. % state for the output functions.  And, it leaves a string on the stack
  362. % as per the output convention.
  363. %
  364. % output.bibitem ==
  365. %  BEGIN
  366. %    newline$
  367. %    write$("\bibitem[")    % for alphabetic labels,
  368. %    write$(label)        % these three lines
  369. %    write$("]{")        % are used
  370. %    write$("\bibitem{")        % this line for numeric labels
  371. %    write$(cite$)
  372. %    write$("}")
  373. %    push "" on stack
  374. %    output.state := before.all
  375. %  END
  376. %
  377. % The fin.entry function finishes off an entry by adding a period to the
  378. % string remaining on the stack.  If the state is still before.all
  379. % then nothing was produced for this entry, so the result will look bad,
  380. % but the user deserves it. (We don't omit the whole entry because the
  381. % entry was cited, and a bibitem is needed to define the citation label.)
  382. %
  383. % fin.entry ==
  384. %  BEGIN
  385. %    write$(add.period$(pop()))
  386. %    newline$
  387. %  END
  388. %
  389. % The new.block function prepares for a new block to be output, and
  390. % new.sentence prepares for a new sentence.
  391. %
  392. % new.block ==
  393. %  BEGIN
  394. %    if output.state <> before.all then
  395. %        output.state := after.block
  396. %    fi
  397. %  END
  398. %
  399. % new.sentence ==
  400. %  BEGIN
  401. %    if output.state <> after.block then
  402. %        if output.state <> before.all then
  403. %        output.state :=  after.sentence
  404. %        fi
  405. %    fi
  406. %  END
  407. %
  408. INTEGERS { output.state before.all mid.sentence after.sentence after.block }
  409. FUNCTION {init.state.consts}
  410. { #0 'before.all :=
  411.   #1 'mid.sentence :=
  412.   #2 'after.sentence :=
  413.   #3 'after.block :=
  414. }
  415. % the variables s and t are temporary string holders
  416. STRINGS { s t }
  417. FUNCTION {output.nonnull}
  418. { 's :=
  419.   output.state mid.sentence =
  420.     { ", " * write$ }
  421.     { output.state after.block =
  422.     { "," * write$
  423.       newline$
  424.       "\newblock " write$
  425.     }
  426.     { output.state before.all =
  427.         'write$
  428.         { add.period$ " " * write$ }
  429.       if$
  430.     }
  431.       if$
  432.       mid.sentence 'output.state :=
  433.     }
  434.   if$
  435.   s
  436. }
  437. FUNCTION {output}
  438. { duplicate$ empty$
  439.     'pop$
  440.     'output.nonnull
  441.   if$
  442. }
  443. FUNCTION {output.check}
  444. { 't :=
  445.   duplicate$ empty$
  446.     { pop$ "empty " t * " in " * cite$ * warning$ }
  447.     'output.nonnull
  448.   if$
  449. }
  450. FUNCTION {output.bibitem}
  451. { newline$
  452.   "\bibitem[" write$
  453.   label write$
  454.   "]{" write$
  455.   cite$ write$
  456.   "}" write$
  457.   newline$
  458.   ""
  459.   before.all 'output.state :=
  460. }
  461. % This function finishes all entries.
  462. FUNCTION {fin.entry}
  463. { add.period$
  464.   write$
  465.   newline$
  466. }
  467. FUNCTION {new.block}
  468. { output.state before.all =
  469.     'skip$
  470.     { after.block 'output.state := }
  471.   if$
  472. }
  473. FUNCTION {new.sentence}
  474. { skip$
  475. }
  476. % These three functions pop one or two (integer) arguments from the stack
  477. % and push a single one, either 0 or 1.
  478. % The 'skip$ in the `and' and `or' functions are used because
  479. % the corresponding if$ would be idempotent
  480. FUNCTION {not}
  481. {   { #0 }
  482.     { #1 }
  483.   if$
  484. }
  485. FUNCTION {and}
  486. {   'skip$
  487.     { pop$ #0 }
  488.   if$
  489. }
  490. FUNCTION {or}
  491. {   { pop$ #1 }
  492.     'skip$
  493.   if$
  494. }
  495. % Sometimes we begin a new block only if the block will be big enough.  The
  496. % new.block.checka function issues a new.block if its argument is nonempty;
  497. % new.block.checkb does the same if either of its TWO arguments is nonempty.
  498. FUNCTION {new.block.checka}
  499. { empty$
  500.     'skip$
  501.     'new.block
  502.   if$
  503. }
  504. FUNCTION {new.block.checkb}
  505. { empty$
  506.   swap$ empty$
  507.   and
  508.     'skip$
  509.     'new.block
  510.   if$
  511. }
  512. % The new.sentence.check functions are analogous.
  513. FUNCTION {new.sentence.checka}
  514. { empty$
  515.     'skip$
  516.     'new.sentence
  517.   if$
  518. }
  519. FUNCTION {new.sentence.checkb}
  520. { empty$
  521.   swap$ empty$
  522.   and
  523.     'skip$
  524.     'new.sentence
  525.   if$
  526. }
  527. % Here are some functions for formatting chunks of an entry.
  528. % By convention they either produce a string that can be followed by
  529. % a comma or period (using add.period$, so it is OK to end in a period),
  530. % or they produce the null string.
  531. %
  532. % A useful utility is the field.or.null function, which checks if the
  533. % argument is the result of pushing a `missing' field (one for which no
  534. % assignment was made when the current entry was read in from the database)
  535. % or the result of pushing a string having no non-white-space characters.
  536. % It returns the null string if so, otherwise it returns the field string.
  537. % Its main (but not only) purpose is to guarantee that what's left on the
  538. % stack is a string rather than a missing field.
  539. %
  540. % field.or.null(s) ==
  541. %  BEGIN
  542. %    if empty$(s) then return ""
  543. %    else return s
  544. %  END
  545. %
  546. % Another helper function is emphasize, which returns the argument emphazised,
  547. % if that is non-empty, otherwise it returns the null string.  Italic
  548. % corrections aren't used, so this function should be used when punctation
  549. % will follow the result.
  550. %
  551. % emphasize(s) ==
  552. %  BEGIN
  553. %    if empty$(s) then return ""
  554. %    else return "{\em " * s * "}"
  555. %
  556. % The format.names function formats the argument (which should be in
  557. % BibTeX name format) into "First Von Last, Junior", separated by commas
  558. % and with an "and" before the last (but ending with "et~al." if the last
  559. % of multiple authors is "others").  This function's argument should always
  560. % contain at least one name.
  561. %
  562. % VAR: nameptr, namesleft, numnames: INTEGER
  563. % pseudoVAR: nameresult: STRING        (it's what's accumulated on the stack)
  564. %
  565. % format.names(s) ==
  566. %  BEGIN
  567. %    nameptr := 1
  568. %    numnames := num.names$(s)
  569. %    namesleft := numnames
  570. %    while namesleft > 0
  571. %      do
  572. %                % for full names:
  573. %        t := format.name$(s, nameptr, "{ff~}{vv~}{ll}{, jj}")
  574. %                % for abbreviated first names:
  575. %        t := format.name$(s, nameptr, "{f.~}{vv~}{ll}{, jj}")
  576. %        if nameptr > 1 then
  577. %        if namesleft > 1 then nameresult := nameresult * ", " * t
  578. %        else if numnames > 2
  579. %               then nameresult := nameresult * ","
  580. %             fi
  581. %             if t = "others"
  582. %               then nameresult := nameresult * " et~al."
  583. %               else nameresult := nameresult * " and " * t
  584. %             fi
  585. %        fi
  586. %        else nameresult := t
  587. %        fi
  588. %        nameptr := nameptr + 1
  589. %        namesleft := namesleft - 1
  590. %      od
  591. %    return nameresult
  592. %  END
  593. %
  594. % The format.authors function returns the result of format.names(author)
  595. % if the author is present, or else it returns the null string
  596. %
  597. % format.authors ==
  598. %  BEGIN
  599. %    if empty$(author) then return ""
  600. %    else return format.names(author)
  601. %    fi
  602. %  END
  603. %
  604. % Format.editors is like format.authors, but it uses the editor field,
  605. % and appends ", editor" or ", editors"
  606. %
  607. % format.editors ==
  608. %  BEGIN
  609. %    if empty$(editor) then return ""
  610. %    else
  611. %        if num.names$(editor) > 1 then
  612. %        return format.names(editor) * ", editors"
  613. %        else
  614. %        return format.names(editor) * ", editor"
  615. %        fi
  616. %    fi
  617. %  END
  618. %
  619. % Other formatting functions are similar, so no "comment version" will be
  620. % given for them.
  621. %
  622. % The `pop$' in this function gets rid of the duplicate `empty' value and
  623. % the `skip$' returns the duplicate field value
  624. FUNCTION {field.or.null}
  625. { duplicate$ empty$
  626.     { pop$ "" }
  627.     'skip$
  628.   if$
  629. }
  630. FUNCTION {emphasize}
  631. { duplicate$ empty$
  632.     { pop$ "" }
  633.     { "{\em " swap$ * "}" * }
  634.   if$
  635. }
  636. FUNCTION {embolden}
  637. { duplicate$ empty$
  638.     { pop$ "" }
  639.     { "{\bf " swap$ * "}" * }
  640.   if$
  641. }
  642. FUNCTION {bracket}
  643. { duplicate$ empty$
  644.     { pop$ "" }
  645.     { "[" swap$ * "]" * }
  646.   if$
  647. }
  648. INTEGERS { nameptr namesleft numnames }
  649. FUNCTION {format.names}
  650. { 's :=
  651.   #1 'nameptr :=
  652.   s num.names$ 'numnames :=
  653.   numnames 'namesleft :=
  654.     { namesleft #0 > }
  655.     { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
  656.       nameptr #1 >
  657.     { namesleft #1 >
  658.         { ", " * t * }
  659.         { numnames #2 >
  660.         { "," * }
  661.         'skip$
  662.           if$
  663.           t "others" =
  664.         { " et~al." * }
  665.         { " and " * t * }
  666.           if$
  667.         }
  668.       if$
  669.     }
  670.     't
  671.       if$
  672.       nameptr #1 + 'nameptr :=
  673.       namesleft #1 - 'namesleft :=
  674.     }
  675.   while$
  676. }
  677. FUNCTION {format.authors}
  678. { author empty$
  679.     { "" }
  680.     { author format.names }
  681.   if$
  682. }
  683. FUNCTION {format.editors}
  684. { editor empty$
  685.     { "" }
  686.     { editor format.names
  687.       editor num.names$ #1 >
  688.     { ", editors" * }
  689.     { ", editor" * }
  690.       if$
  691.     }
  692.   if$
  693. }
  694. FUNCTION {format.edited}
  695. { editor empty$
  696.     { "" }
  697.     { "edited by " editor format.names * }
  698.   if$
  699. }
  700. % The format.title function is used for non-book-like titles.
  701. % For most styles we convert to lowercase (except for the very first letter,
  702. % and except for the first one after a colon (followed by whitespace)),
  703. % and hope the user has brace-surrounded words that need to stay capitilized;
  704. % for some styles, however, we leave it as it is in the database.
  705. FUNCTION {format.title}
  706. { title empty$
  707.     { "" }
  708.     { title "t" change.case$ }
  709.   if$
  710. }
  711. % By default, BibTeX sets the global integer variable global.max$ to the BibTeX
  712. % constant glob_str_size, the maximum length of a global string variable.
  713. % Analogously, BibTeX sets the global integer variable entry.max$ to
  714. % ent_str_size, the maximum length of an entry string variable.
  715. % The style designer may change these if necessary (but this is unlikely)
  716. % The n.dashify function makes each single `-' in a string a double `--'
  717. % if it's not already
  718. %
  719. % pseudoVAR: pageresult: STRING        (it's what's accumulated on the stack)
  720. %
  721. % n.dashify(s) ==
  722. %  BEGIN
  723. %    t := s
  724. %    pageresult := ""
  725. %    while (not empty$(t))
  726. %      do
  727. %        if (first character of t = "-")
  728. %          then
  729. %        if (next character isn't)
  730. %          then
  731. %            pageresult := pageresult * "--"
  732. %            t := t with the "-" removed
  733. %          else
  734. %            while (first character of t = "-")
  735. %              do
  736. %            pageresult := pageresult * "-"
  737. %            t := t with the "-" removed
  738. %              od
  739. %        fi
  740. %          else
  741. %        pageresult := pageresult * the first character
  742. %        t := t with the first character removed
  743. %        fi
  744. %      od
  745. %    return pageresult
  746. %  END
  747. FUNCTION {n.dashify}
  748. { 't :=
  749.   ""
  750.     { t empty$ not }
  751.     { t #1 #1 substring$ "-" =
  752.     { t #1 #2 substring$ "--" = not
  753.         { "--" *
  754.           t #2 global.max$ substring$ 't :=
  755.         }
  756.         {   { t #1 #1 substring$ "-" = }
  757.         { "-" *
  758.           t #2 global.max$ substring$ 't :=
  759.         }
  760.           while$
  761.         }
  762.       if$
  763.     }
  764.     { t #1 #1 substring$ *
  765.       t #2 global.max$ substring$ 't :=
  766.     }
  767.       if$
  768.     }
  769.   while$
  770. }
  771. FUNCTION {first.page}
  772. { 't :=
  773.   ""
  774.     {  t empty$ not t #1 #1 substring$ "-" = not and }
  775.     { t #1 #1 substring$ *
  776.       t #2 global.max$ substring$ 't :=
  777.     }
  778.   while$
  779. }
  780. % The format.date function is for the month and year, but we give a warning if
  781. % there's an empty year but the month is there, and we return the empty string
  782. % if they're both empty.
  783. FUNCTION {format.date}
  784. { year empty$
  785.     { month empty$
  786.     { "" }
  787.     { "there's a month but no year in " cite$ * warning$
  788.       month
  789.     }
  790.       if$
  791.     }
  792.     { month empty$
  793.     'year
  794.     { month " " * year * }
  795.       if$
  796.     }
  797.   if$
  798. }
  799. % The format.btitle is for formatting the title field when it is a book-like
  800. % entry---the style used here keeps it in uppers-and-lowers and emphasizes it.
  801. FUNCTION {format.btitle}
  802. { title emphasize
  803. }
  804. % For several functions we'll need to connect two strings with a
  805. % tie (~) if the second one isn't very long (fewer than 3 characters).
  806. % The tie.or.space.connect function does that.  It concatenates the two
  807. % strings on top of the stack, along with either a tie or space between
  808. % them, and puts this concatenation back onto the stack:
  809. %
  810. % tie.or.space.connect(str1,str2) ==
  811. %    BEGIN
  812. %    if text.length$(str2) < 3
  813. %      then return the concatenation of str1, "~", and str2
  814. %      else return the concatenation of str1, " ", and str2
  815. %    END
  816. FUNCTION {tie.or.space.connect}
  817. { duplicate$ text.length$ #3 <
  818.     { "~" }
  819.     { " " }
  820.   if$
  821.   swap$ * *
  822. }
  823. % The either.or.check function complains if both fields or an either-or pair
  824. % are nonempty.
  825. %
  826. % either.or.check(t,s) ==
  827. %  BEGIN
  828. %    if empty$(s) then
  829. %        warning$(can't use both " * t * " fields in " * cite$)
  830. %    fi
  831. %  END
  832. FUNCTION {either.or.check}
  833. { empty$
  834.     'pop$
  835.     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  836.   if$
  837. }
  838. % The format.bvolume function is for formatting the volume and perhaps
  839. % series name of a multivolume work.  If both a volume and a series field
  840. % are there, we assume the series field is the title of the whole multivolume
  841. % work (the title field should be the title of the thing being referred to),
  842. % and we add an "of <series>".  This function is called in mid-sentence.
  843. FUNCTION {format.bvolume}
  844. { volume empty$
  845.     { "" }
  846.     { "volume" volume tie.or.space.connect
  847.       series empty$
  848.     'skip$
  849.     { " of " * series emphasize * }
  850.       if$
  851.       "volume and number" number either.or.check
  852.     }
  853.   if$
  854. }
  855. % The format.number.series function is for formatting the series name
  856. % and perhaps number of a work in a series.  This function is similar to
  857. % format.bvolume, although for this one the series must exist (and the
  858. % volume must not exist).  If the number field is empty we output either
  859. % the series field unchanged if it exists or else the null string.
  860. % If both the number and series fields are there we assume the series field
  861. % gives the name of the whole series (the title field should be the title
  862. % of the work being one referred to), and we add an "in <series>".
  863. % We capitilize Number when this function is used at the beginning of a block.
  864. FUNCTION {format.number.series}
  865. { volume empty$
  866.     { number empty$
  867.     { series field.or.null }
  868.     { output.state mid.sentence =
  869.         { "number" }
  870.         { "Number" }
  871.       if$
  872.       number tie.or.space.connect
  873.       series empty$
  874.         { "there's a number but no series in " cite$ * warning$ }
  875.         { " in " * series * }
  876.       if$
  877.     }
  878.       if$
  879.     }
  880.     { "" }
  881.   if$
  882. }
  883. % The format.edition function appends " edition" to the edition, if present.
  884. % We lowercase the edition (it should be something like "Third"), because
  885. % this doesn't start a sentence.
  886. FUNCTION {format.edition}
  887. { edition empty$
  888.     { "" }
  889.     { output.state mid.sentence =
  890.     { edition "l" change.case$ " edition" * }
  891.     { edition "t" change.case$ " edition" * }
  892.       if$
  893.     }
  894.   if$
  895. }
  896. % The format.pages function is used for formatting a page range in a book
  897. % (and in rare circumstances, an article).
  898. %
  899. % The multi.page.check function examines the page field for a "-" or "," or "+"
  900. % so that format.pages can use "page" instead of "pages" if none exists.
  901. % Note: global.max$ here means "take the rest of the string"
  902. %
  903. % VAR: multiresult: INTEGER    (actually, a boolean)
  904. %
  905. % multi.page.check(s) ==
  906. %  BEGIN
  907. %    t := s
  908. %    multiresult := false
  909. %    while ((not multiresult) and (not empty$(t)))
  910. %      do
  911. %        if (first character of t = "-" or "," or "+")
  912. %          then multiresult := true
  913. %          else t := t with the first character removed
  914. %        fi
  915. %      od
  916. %    return multiresult
  917. %  END
  918. INTEGERS { multiresult }
  919. FUNCTION {multi.page.check}
  920. { 't :=
  921.   #0 'multiresult :=
  922.     { multiresult not
  923.       t empty$ not
  924.       and
  925.     }
  926.     { t #1 #1 substring$
  927.       duplicate$ "-" =
  928.       swap$ duplicate$ "," =
  929.       swap$ "+" =
  930.       or or
  931.     { #1 'multiresult := }
  932.     { t #2 global.max$ substring$ 't := }
  933.       if$
  934.     }
  935.   while$
  936.   multiresult
  937. }
  938. % This function doesn't begin a sentence so "pages" isn't capitalized.
  939. % Other functions that use this should keep that in mind.
  940. FUNCTION {format.pages}
  941. { pages empty$
  942.     { "" }
  943.     { pages multi.page.check
  944.     { "pp." pages n.dashify tie.or.space.connect }
  945.     { "p." pages tie.or.space.connect }
  946.       if$
  947.     }
  948.   if$
  949. }
  950. FUNCTION {format.pages.a}
  951. { pages empty$
  952.     { "" }
  953.     { "p." pages first.page tie.or.space.connect }
  954.   if$
  955. }
  956. % The format.vol.num.pages function is for the volume, number, and page range
  957. % of a journal article.  We use the format:  vol(number):pages, with some
  958. % variations for empty fields.  This doesn't begin a sentence.
  959. FUNCTION {format.vol.num.pages}
  960. { volume field.or.null embolden
  961.   pages empty$
  962.     'skip$
  963.     { duplicate$ empty$
  964.     { pop$ format.pages.a }
  965.     { ":" * pages first.page * }
  966.       if$
  967.     }
  968.   if$
  969. }
  970. % The format.chapter.pages, if the chapter is present, puts whatever is in the
  971. % type field (or else "chapter" if type is empty) in front of a chapter number.
  972. % It then appends the pages, if present.  This doesn't begin a sentence.
  973. FUNCTION {format.chapter.pages}
  974. { chapter empty$
  975.     'format.pages
  976.     { type empty$
  977.     { "chapter" }
  978.     { type "l" change.case$ }
  979.       if$
  980.       chapter tie.or.space.connect
  981.       pages empty$
  982.     'skip$
  983.     { ", " * format.pages * }
  984.       if$
  985.     }
  986.   if$
  987. }
  988. % The format.in.ed.booktitle function is used for starting out a sentence
  989. % that begins "In <booktitle>", putting an editor before the title if one
  990. % exists.
  991. FUNCTION {format.in.ed.booktitle}
  992. { booktitle empty$
  993.     { "" }
  994.     { editor empty$
  995.     { "in " booktitle emphasize * }
  996.     { "in " booktitle emphasize * ", " * format.edited * }
  997.       if$
  998.     }
  999.   if$
  1000. }
  1001. % The function empty.misc.check complains if all six fields are empty, and
  1002. % if there's been no sorting or alphabetic-label complaint.
  1003. FUNCTION {empty.misc.check}
  1004. { author empty$ title empty$ howpublished empty$
  1005.   month empty$ year empty$ note empty$
  1006.   and and and and and
  1007.   key empty$ not and
  1008.     { "all relevant fields are empty in " cite$ * warning$ }
  1009.     'skip$
  1010.   if$
  1011. }
  1012. % The function format.thesis.type returns either the (case-changed) type field,
  1013. % if it is defined, or else the default string already on the stack
  1014. % (like "Master's thesis" or "PhD thesis").
  1015. FUNCTION {format.thesis.type}
  1016. { type empty$
  1017.     'skip$
  1018.     { pop$
  1019.       type "t" change.case$
  1020.     }
  1021.   if$
  1022. }
  1023. % The function format.tr.number makes a string starting with "Technical Report"
  1024. % (or type, if that field is defined), followed by the number if there is one;
  1025. % it returns the starting part (with a case change) even if there is no number.
  1026. % This is used at the beginning of a sentence.
  1027. FUNCTION {format.tr.number}
  1028. { type empty$
  1029.     { "Technical Report" }
  1030.     'type
  1031.   if$
  1032.   number empty$
  1033.     { "t" change.case$ }
  1034.     { number tie.or.space.connect }
  1035.   if$
  1036. }
  1037. % Now come the cross-referencing functions (these are invoked because
  1038. % one entry in the database file(s) cross-references another, by giving
  1039. % the other entry's database key in a `crossref' field).  This feature
  1040. % allows one or more titled things that are part of a larger titled
  1041. % thing to cross-reference the larger thing.  These styles allow for
  1042. % five posibilities: (1) an ARTICLE may cross-reference an ARTICLE;
  1043. % (2) a BOOK, (3) INBOOK, or (4) INCOLLECTION may cross-reference a BOOK;
  1044. % or (5) an INPROCEEDINGS may cross-reference a PROCEEDINGS.
  1045. % Each of these is explained in more detail later.
  1046. %
  1047. % An ARTICLE entry type may cross reference another ARTICLE (this is
  1048. % intended for when an entire journal is devoted to a single topic---
  1049. % but since there is no JOURNAL entry type, the journal, too, should be
  1050. % classified as an ARTICLE but without the author and title fields).
  1051. % This will result in two warning messages for the journal's entry
  1052. % if it's included in the reference list, but such is life.
  1053. %
  1054. % format.article.crossref ==
  1055. %  BEGIN
  1056. %    if empty$(key) then
  1057. %        if empty$(journal) then
  1058. %        warning$("need key or journal for " * cite$ *
  1059. %                        " to crossref " * crossref)
  1060. %        return(" \cite{" * crossref * "}")
  1061. %        else
  1062. %        return("In " * emphazise.correct (journal) *
  1063. %                        " \cite{" * crossref * "}")
  1064. %        fi
  1065. %    else
  1066. %        return("In " * key * " \cite{" * crossref * "}")
  1067. %    fi
  1068. %  END
  1069. %
  1070. % The other cross-referencing functions are similar, so no "comment version"
  1071. % will be given for them.
  1072. FUNCTION {format.article.crossref}
  1073. { key empty$
  1074.     { journal empty$
  1075.     { "need key or journal for " cite$ * " to crossref " * crossref *
  1076.       warning$
  1077.       ""
  1078.     }
  1079.     { "In " journal * }
  1080.       if$
  1081.     }
  1082.     { "In " key * }
  1083.   if$
  1084.   " \cite{" * crossref * "}" *
  1085. }
  1086. % We use just the last names of editors for a cross reference: either
  1087. % "editor", or "editor1 and editor2", or "editor1 et~al." depending on
  1088. % whether there are one, or two, or more than two editors.
  1089. FUNCTION {format.crossref.editor}
  1090. { editor #1 "{vv~}{ll}" format.name$
  1091.   editor num.names$ duplicate$
  1092.   #2 >
  1093.     { pop$ " et~al." * }
  1094.     { #2 <
  1095.     'skip$
  1096.     { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  1097.         { " et~al." * }
  1098.         { " and " * editor #2 "{vv~}{ll}" format.name$ * }
  1099.       if$
  1100.     }
  1101.       if$
  1102.     }
  1103.   if$
  1104. }
  1105. % A BOOK (or INBOOK) entry type (assumed to be for a single volume in a
  1106. % multivolume work) may cross reference another BOOK (the entire multivolume).
  1107. % Usually there will be an editor, in which case we use that to construct the
  1108. % cross reference; otherwise we use a nonempty key field or else the series
  1109. % field (since the series gives the title of the multivolume work).
  1110. FUNCTION {format.book.crossref}
  1111. { volume empty$
  1112.     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
  1113.       "In "
  1114.     }
  1115.     { "Volume" volume tie.or.space.connect
  1116.       " of " *
  1117.     }
  1118.   if$
  1119.   editor empty$
  1120.   editor field.or.null author field.or.null =
  1121.   or
  1122.     { key empty$
  1123.     { series empty$
  1124.         { "need editor, key, or series for " cite$ * " to crossref " *
  1125.           crossref * warning$
  1126.           "" *
  1127.         }
  1128.         { "{\em " * series * "\/}" * }
  1129.       if$
  1130.     }
  1131.     { key * }
  1132.       if$
  1133.     }
  1134.     { format.crossref.editor * }
  1135.   if$
  1136.   " \cite{" * crossref * "}" *
  1137. }
  1138. % An INCOLLECTION entry type may cross reference a BOOK (assumed to be the
  1139. % collection), or an INPROCEEDINGS may cross reference a PROCEEDINGS.
  1140. % Often there will be an editor, in which case we use that to construct
  1141. % the cross reference; otherwise we use a nonempty key field or else
  1142. % the booktitle field (which gives the cross-referenced work's title).
  1143. FUNCTION {format.incoll.inproc.crossref}
  1144. { editor empty$
  1145.   editor field.or.null author field.or.null =
  1146.   or
  1147.     { key empty$
  1148.     { booktitle empty$
  1149.         { "need editor, key, or booktitle for " cite$ * " to crossref " *
  1150.           crossref * warning$
  1151.           ""
  1152.         }
  1153.         { "In {\em " booktitle * "\/}" * }
  1154.       if$
  1155.     }
  1156.     { "In " key * }
  1157.       if$
  1158.     }
  1159.     { "In " format.crossref.editor * }
  1160.   if$
  1161.   " \cite{" * crossref * "}" *
  1162. }
  1163. % Now we define the type functions for all entry types that may appear
  1164. % in the .BIB file---e.g., functions like `article' and `book'.  These
  1165. % are the routines that actually generate the .BBL-file output for
  1166. % the entry.  These must all precede the READ command.  In addition, the
  1167. % style designer should have a function `default.type' for unknown types.
  1168. % Note: The fields (within each list) are listed in order of appearance,
  1169. % except as described for an `inbook' or a `proceedings'.
  1170. %
  1171. % The article function is for an article in a journal.  An article may
  1172. % CROSSREF another article.
  1173. %    Required fields: author, title, journal, year
  1174. %    Optional fields: volume, number, pages, month, note
  1175. %
  1176. % article ==
  1177. %  BEGIN
  1178. %    output.bibitem
  1179. %    output.check(format.authors,"author")
  1180. %    new.block
  1181. %    output.check(format.title,"title")
  1182. %    new.block
  1183. %    if missing$(crossref) then
  1184. %        output.check(emphasize(journal),"journal")
  1185. %        output(format.vol.num.pages)
  1186. %        output.check(format.date,"year")
  1187. %       else
  1188. %        output.nonnull(format.article.crossref)
  1189. %        output(format.pages)
  1190. %    fi
  1191. %    new.block
  1192. %    output(note)
  1193. %    fin.entry
  1194. %  END
  1195. %
  1196. % The book function is for a whole book.  A book may CROSSREF another book.
  1197. %    Required fields: author or editor, title, publisher, year
  1198. %    Optional fields: volume or number, series, address, edition, month,
  1199. %            note
  1200. %
  1201. % book ==
  1202. %  BEGIN
  1203. %    if empty$(author) then output.check(format.editors,"author and editor")
  1204. %    else    output.check(format.authors,"author")
  1205. %        if missing$(crossref) then
  1206. %            either.or.check("author and editor",editor)
  1207. %        fi
  1208. %    fi
  1209. %    new.block
  1210. %    output.check(format.btitle,"title")
  1211. %    if missing$(crossref) then
  1212. %        output(format.bvolume)
  1213. %        new.block
  1214. %        output(format.number.series)
  1215. %        new.sentence
  1216. %        output.check(publisher,"publisher")
  1217. %        output(address)
  1218. %       else
  1219. %        new.block
  1220. %        output.nonnull(format.book.crossref)
  1221. %    fi
  1222. %    output(format.edition)
  1223. %    output.check(format.date,"year")
  1224. %    new.block
  1225. %    output(note)
  1226. %    fin.entry
  1227. %  END
  1228. %
  1229. % The other entry functions are all quite similar, so no "comment version"
  1230. % will be given for them.
  1231. FUNCTION {article}
  1232. { output.bibitem
  1233.   format.authors "author" output.check
  1234.   new.block
  1235.   crossref missing$
  1236.     { journal "journal" output.check
  1237.       format.vol.num.pages output
  1238.       format.date "year" output.check
  1239.     }
  1240.     { format.article.crossref output.nonnull
  1241.       format.pages output
  1242.     }
  1243.   if$
  1244.   new.block
  1245.   note output
  1246.   fin.entry
  1247. }
  1248. FUNCTION {book}
  1249. { output.bibitem
  1250.   author empty$
  1251.     { format.editors "author and editor" output.check }
  1252.     { format.authors output.nonnull
  1253.       crossref missing$
  1254.     { "author and editor" editor either.or.check }
  1255.     'skip$
  1256.       if$
  1257.     }
  1258.   if$
  1259.   new.block
  1260.   format.btitle "title" output.check
  1261.   crossref missing$
  1262.     { format.bvolume output
  1263.       new.block
  1264.       format.number.series output
  1265.       new.sentence
  1266.       publisher "publisher" output.check
  1267.       address output
  1268.     }
  1269.     { new.block
  1270.       format.book.crossref output.nonnull
  1271.     }
  1272.   if$
  1273.   format.edition output
  1274.   format.date "year" output.check
  1275.   new.block
  1276.   note output
  1277.   fin.entry
  1278. }
  1279. % A booklet is a bound thing without a publisher or sponsoring institution.
  1280. %    Required: title
  1281. %    Optional: author, howpublished, address, month, year, note
  1282. FUNCTION {booklet}
  1283. { output.bibitem
  1284.   format.authors output
  1285.   new.block
  1286.   format.title "title" output.check
  1287.   howpublished address new.block.checkb
  1288.   howpublished output
  1289.   address output
  1290.   format.date output
  1291.   new.block
  1292.   note output
  1293.   fin.entry
  1294. }
  1295. % For the conference entry type, see inproceedings.
  1296. % An inbook is a piece of a book: either a chapter and/or a page range.
  1297. % It may CROSSREF a book.  If there's no volume field, the type field
  1298. % will come before number and series.
  1299. %    Required: author or editor, title, chapter and/or pages, publisher,year
  1300. %    Optional: volume or number, series, type, address, edition, month, note
  1301. FUNCTION {inbook}
  1302. { output.bibitem
  1303.   author empty$
  1304.     { format.editors "author and editor" output.check }
  1305.     { format.authors output.nonnull
  1306.       crossref missing$
  1307.     { "author and editor" editor either.or.check }
  1308.     'skip$
  1309.       if$
  1310.     }
  1311.   if$
  1312.   new.block
  1313.   format.btitle "title" output.check
  1314.   crossref missing$
  1315.     { format.bvolume output
  1316.       format.chapter.pages "chapter and pages" output.check
  1317.       new.block
  1318.       format.number.series output
  1319.       new.sentence
  1320.       publisher "publisher" output.check
  1321.       address output
  1322.     }
  1323.     { format.chapter.pages "chapter and pages" output.check
  1324.       new.block
  1325.       format.book.crossref output.nonnull
  1326.     }
  1327.   if$
  1328.   format.edition output
  1329.   format.date "year" output.check
  1330.   new.block
  1331.   note output
  1332.   fin.entry
  1333. }
  1334. % An incollection is like inbook, but where there is a separate title
  1335. % for the referenced thing (and perhaps an editor for the whole).
  1336. % An incollection may CROSSREF a book.
  1337. %    Required: author, title, booktitle, publisher, year
  1338. %    Optional: editor, volume or number, series, type, chapter, pages,
  1339. %            address, edition, month, note
  1340. FUNCTION {incollection}
  1341. { output.bibitem
  1342.   format.authors "author" output.check
  1343.   new.block
  1344.   format.title "title" output.check
  1345.   new.block
  1346.   crossref missing$
  1347.     { format.in.ed.booktitle "booktitle" output.check
  1348.       format.bvolume output
  1349.       format.number.series output
  1350.       format.chapter.pages output
  1351.       new.sentence
  1352.       publisher "publisher" output.check
  1353.       address output
  1354.       format.edition output
  1355.       format.date "year" output.check
  1356.     }
  1357.     { format.incoll.inproc.crossref output.nonnull
  1358.       format.chapter.pages output
  1359.     }
  1360.   if$
  1361.   new.block
  1362.   note output
  1363.   fin.entry
  1364. }
  1365. % An inproceedings is an article in a conference proceedings, and it may
  1366. % CROSSREF a proceedings.  If there's no address field, the month (& year)
  1367. % will appear just before note.
  1368. %    Required: author, title, booktitle, year
  1369. %    Optional: editor, volume or number, series, pages, address, month,
  1370. %            organization, publisher, note
  1371. FUNCTION {inproceedings}
  1372. { output.bibitem
  1373.   format.authors "author" output.check
  1374.   new.block
  1375.   format.title "title" output.check
  1376.   new.block
  1377.   crossref missing$
  1378.     { format.in.ed.booktitle "booktitle" output.check
  1379.       format.bvolume output
  1380.       format.number.series output
  1381.       format.pages output
  1382.       address empty$
  1383.     { organization publisher new.sentence.checkb
  1384.       organization output
  1385.       publisher output
  1386.       format.date "year" output.check
  1387.     }
  1388.     { address output.nonnull
  1389.       format.date "year" output.check
  1390.       new.sentence
  1391.       organization output
  1392.       publisher output
  1393.     }
  1394.       if$
  1395.     }
  1396.     { format.incoll.inproc.crossref output.nonnull
  1397.       format.pages output
  1398.     }
  1399.   if$
  1400.   new.block
  1401.   note output
  1402.   fin.entry
  1403. }
  1404. % The conference function is included for Scribe compatibility.
  1405. FUNCTION {conference} { inproceedings }
  1406. % A manual is technical documentation.
  1407. %    Required: title
  1408. %    Optional: author, organization, address, edition, month, year, note
  1409. FUNCTION {manual}
  1410. { output.bibitem
  1411.   author empty$
  1412.     { organization empty$
  1413.     'skip$
  1414.     { organization output.nonnull
  1415.       address output
  1416.     }
  1417.       if$
  1418.     }
  1419.     { format.authors output.nonnull }
  1420.   if$
  1421.   new.block
  1422.   format.btitle "title" output.check
  1423.   author empty$
  1424.     { organization empty$
  1425.     { address new.block.checka
  1426.       address output
  1427.     }
  1428.     'skip$
  1429.       if$
  1430.     }
  1431.     { organization address new.block.checkb
  1432.       organization output
  1433.       address output
  1434.     }
  1435.   if$
  1436.   format.edition output
  1437.   format.date output
  1438.   new.block
  1439.   note output
  1440.   fin.entry
  1441. }
  1442. % A mastersthesis is a Master's thesis.
  1443. %    Required: author, title, school, year
  1444. %    Optional: type, address, month, note
  1445. FUNCTION {mastersthesis}
  1446. { output.bibitem
  1447.   format.authors "author" output.check
  1448.   new.block
  1449.   format.title "title" output.check
  1450.   new.block
  1451.   "Master's thesis" format.thesis.type output.nonnull
  1452.   school "school" output.check
  1453.   address output
  1454.   format.date "year" output.check
  1455.   new.block
  1456.   note output
  1457.   fin.entry
  1458. }
  1459. % A misc is something that doesn't fit elsewhere.
  1460. %    Required: at least one of the `optional' fields
  1461. %    Optional: author, title, howpublished, month, year, note
  1462. FUNCTION {misc}
  1463. { output.bibitem
  1464.   format.authors output
  1465.   title howpublished new.block.checkb
  1466.   format.title output
  1467.   howpublished new.block.checka
  1468.   howpublished output
  1469.   format.date output
  1470.   new.block
  1471.   note output
  1472.   fin.entry
  1473.   empty.misc.check
  1474. }
  1475. % A phdthesis is like a mastersthesis.
  1476. %    Required: author, title, school, year
  1477. %    Optional: type, address, month, note
  1478. FUNCTION {phdthesis}
  1479. { output.bibitem
  1480.   format.authors "author" output.check
  1481.   new.block
  1482.   format.btitle "title" output.check
  1483.   new.block
  1484.   "PhD thesis" format.thesis.type output.nonnull
  1485.   school "school" output.check
  1486.   address output
  1487.   format.date "year" output.check
  1488.   new.block
  1489.   note output
  1490.   fin.entry
  1491. }
  1492. % A proceedings is a conference proceedings.
  1493. % If there is an organization but no editor field, the organization will
  1494. % appear as the first optional field (we try to make the first block nonempty);
  1495. % if there's no address field, the month (& year) will appear just before note.
  1496. %    Required: title, year
  1497. %    Optional: editor, volume or number, series, address, month,
  1498. %            organization, publisher, note
  1499. FUNCTION {proceedings}
  1500. { output.bibitem
  1501.   editor empty$
  1502.     { organization output }
  1503.     { format.editors output.nonnull }
  1504.   if$
  1505.   new.block
  1506.   format.btitle "title" output.check
  1507.   format.bvolume output
  1508.   format.number.series output
  1509.   address empty$
  1510.     { editor empty$
  1511.     { publisher new.sentence.checka }
  1512.     { organization publisher new.sentence.checkb
  1513.       organization output
  1514.     }
  1515.       if$
  1516.       publisher output
  1517.       format.date "year" output.check
  1518.     }
  1519.     { address output.nonnull
  1520.       format.date "year" output.check
  1521.       new.sentence
  1522.       editor empty$
  1523.     'skip$
  1524.     { organization output }
  1525.       if$
  1526.       publisher output
  1527.     }
  1528.   if$
  1529.   new.block
  1530.   note output
  1531.   fin.entry
  1532. }
  1533. % A techreport is a technical report.
  1534. %    Required: author, title, institution, year
  1535. %    Optional: type, number, address, month, note
  1536. FUNCTION {techreport}
  1537. { output.bibitem
  1538.   format.authors "author" output.check
  1539.   new.block
  1540.   format.title "title" output.check
  1541.   new.block
  1542.   format.tr.number output.nonnull
  1543.   institution "institution" output.check
  1544.   address output
  1545.   format.date "year" output.check
  1546.   new.block
  1547.   note output
  1548.   fin.entry
  1549. }
  1550. % An unpublished is something that hasn't been published.
  1551. %    Required: author, title, note
  1552. %    Optional: month, year
  1553. FUNCTION {unpublished}
  1554. { output.bibitem
  1555.   format.authors "author" output.check
  1556.   new.block
  1557.   format.title "title" output.check
  1558.   new.block
  1559.   note "note" output.check
  1560.   format.date output
  1561.   fin.entry
  1562. }
  1563. % We use entry type `misc' for an unknown type; BibTeX gives a warning.
  1564. FUNCTION {default.type} { misc }
  1565. % Here are macros for common things that may vary from style to style.
  1566. % Users are encouraged to use these macros.
  1567. %
  1568. % Months are either written out in full or abbreviated
  1569. MACRO {jan} {"Jan."}
  1570. MACRO {feb} {"Feb."}
  1571. MACRO {mar} {"Mar."}
  1572. MACRO {apr} {"Apr."}
  1573. MACRO {may} {"May"}
  1574. MACRO {jun} {"June"}
  1575. MACRO {jul} {"July"}
  1576. MACRO {aug} {"Aug."}
  1577. MACRO {sep} {"Sept."}
  1578. MACRO {oct} {"Oct."}
  1579. MACRO {nov} {"Nov."}
  1580. MACRO {dec} {"Dec."}
  1581. % Journals are either written out in full or abbreviated;
  1582. % the abbreviations are like those found in ACM publications.
  1583. %
  1584. % To get a completely different set of abbreviations, it may be best to make
  1585. % a separate .bib file with nothing but those abbreviations; users could then
  1586. % include that file name as the first argument to the \bibliography command
  1587. MACRO {acmcs} {"ACM Comput. Surv."}
  1588. MACRO {acta} {"Acta Inf."}
  1589. MACRO {cacm} {"Commun. ACM"}
  1590. MACRO {ibmjrd} {"IBM J. Res. Dev."}
  1591. MACRO {ibmsj} {"IBM Syst.~J."}
  1592. MACRO {ieeese} {"IEEE Trans. Softw. Eng."}
  1593. MACRO {ieeetc} {"IEEE Trans. Comput."}
  1594. MACRO {ieeetcad}
  1595.  {"IEEE Trans. Comput.-Aided Design Integrated Circuits"}
  1596. MACRO {ipl} {"Inf. Process. Lett."}
  1597. MACRO {jacm} {"J.~ACM"}
  1598. MACRO {jcss} {"J.~Comput. Syst. Sci."}
  1599. MACRO {scp} {"Sci. Comput. Programming"}
  1600. MACRO {sicomp} {"SIAM J. Comput."}
  1601. MACRO {tocs} {"ACM Trans. Comput. Syst."}
  1602. MACRO {tods} {"ACM Trans. Database Syst."}
  1603. MACRO {tog} {"ACM Trans. Gr."}
  1604. MACRO {toms} {"ACM Trans. Math. Softw."}
  1605. MACRO {toois} {"ACM Trans. Office Inf. Syst."}
  1606. MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."}
  1607. MACRO {tcs} {"Theoretical Comput. Sci."}
  1608. %% /usr/local/lib/tex/bibtex/phyjfull.btx, Tue Jun 30 08:37:48 1992
  1609. %% Edit by Nelson H. F. Beebe <beebe@alfred.math.utah.edu>
  1610. %% Change file names in leading comment
  1611. % Journal Title Abbreviations from the Physical Review Style and Notation
  1612. %    Guide, July, 1983, in BAPS Vol. 28.
  1613. %  Selected by Cris Barnes and Charles Karney, March 1988
  1614. % IMPORTANT!! Don't make changes to this file without making the
  1615. %           corresponding changes to
  1616. %            phyjabb.bib
  1617. %            phyjabb.btx
  1618. MACRO {advp} {"Advances in Physics"}
  1619. MACRO {ajp} {"American Journal of Physics"}
  1620. MACRO {ao} {"Applied Optics"}
  1621. MACRO {apl} {"Applied Physics Letters"}
  1622. MACRO {apj} {"Astrophysical Journal"}
  1623. MACRO {baps} {"Bulletin of the American Physical Society"}
  1624. MACRO {cpc} {"Computer Physics Communications"}
  1625. MACRO {cppcf} {"Comments on Plasma Physics and Controlled Fusion"}
  1626. MACRO {fed} {"Fusion Engineering and Design"}
  1627. MACRO {ft} {"Fusion Technology"}
  1628. MACRO {ieeens} {"IEEE Transactions on Nuclear Science"}
  1629. MACRO {ieeeps} {"IEEE Transactions on Plasma Science"}
  1630. MACRO {ijimw} {"International Journal of Infrared and Millimeter Waves"}
  1631. MACRO {ip} {"Infrared Physics"}
  1632. MACRO {jap} {"Journal of Applied Physics"}
  1633. MACRO {jcp} {"Journal of Computational Physics"}
  1634. MACRO {jetp} {"Soviet Physics-JETP"}
  1635. MACRO {jfe} {"Journal of Fusion Energy"}
  1636. MACRO {jfm} {"Journal of Fluid Mechanics"}
  1637. MACRO {jgr} {"Journal of Geophysical Research"}
  1638. MACRO {jmp} {"Journal of Mathematical Physics"}
  1639. MACRO {jne} {"Journal of Nuclear Energy"}
  1640. MACRO {jnec} {"Journal of Nuclear Energy, Part C: Plasma Physics, Accelerators, Thermonuclear Research"}
  1641. MACRO {jnm} {"Journal of Nuclear Materials"}
  1642. MACRO {josa} {"Journal of the Optical Society of America"}
  1643. MACRO {jpp} {"Journal of Plasma Physics"}
  1644. MACRO {jpsj} {"Journal of the Physical Society of Japan"}
  1645. MACRO {jvst} {"Journal of Vacuum Science and Technology"}
  1646. MACRO {nedf} {"Nuclear Engineering and Design/Fusion"}
  1647. MACRO {nf} {"Nuclear Fusion"}
  1648. MACRO {nim} {"Nuclear Instruments and Methods"}
  1649. MACRO {nimpr} {"Nuclear Instruments and Methods in Physics Research"}
  1650. MACRO {nt/f} {"Nuclear Technology/Fusion"}
  1651. MACRO {pf} {"Physics of Fluids"}
  1652. MACRO {pfa} {"Physics of Fluids A: Fluid Dynamics"}
  1653. MACRO {pfb} {"Physics of Fluids B: Plasma Physics"}
  1654. MACRO {pl} {"Physics Letters"}
  1655. MACRO {pla} {"Physics Letters A"}
  1656. MACRO {pnas} {"Proceedings of the National Academy of Sciences of the USA"}
  1657. MACRO {pp} {"Plasma Physics"}
  1658. MACRO {ppcf} {"Plasma Physics and Controlled Fusion"}
  1659. MACRO {prl} {"Physical Review Letters"}
  1660. MACRO {pr} {"Physical Review"}
  1661. MACRO {pra} {"Physical Review A: General Physics"}
  1662. MACRO {ps} {"Physica Scripta"}
  1663. MACRO {rmp} {"Reviews of Modern Physics"}
  1664. MACRO {rsi} {"Review of Scientific Instruments"}
  1665. MACRO {sjpp} {"Soviet Journal of Plasma Phys."}
  1666. MACRO {spd} {"Soviet Physics-Doklady"}
  1667. MACRO {sptp} {"Soviet Physics-Technical Physics"}
  1668. MACRO {spu} {"Soviet Physics-Uspeki"}
  1669. % Now we read in the .BIB entries.
  1670. READ
  1671. % The sortify function converts to lower case after purify$ing; it's
  1672. % used in sorting and in computing alphabetic labels after sorting
  1673. %
  1674. % The chop.word(w,len,s) function returns either s or, if the first len
  1675. % letters of s equals w (this comparison is done in the third line of the
  1676. % function's definition), it returns that part of s after w.
  1677. FUNCTION {sortify}
  1678. { purify$
  1679.   "l" change.case$
  1680. }
  1681. INTEGERS { len }
  1682. FUNCTION {chop.word}
  1683. { 's :=
  1684.   'len :=
  1685.   s #1 len substring$ =
  1686.     { s len #1 + global.max$ substring$ }
  1687.     's
  1688.   if$
  1689. }
  1690. % This long comment applies only to alphabetic labels
  1691. %
  1692. % The format.lab.names function makes a short label by using the initials of
  1693. % the von and Last parts of the names (but if there are more than four names,
  1694. % (i.e., people) it truncates after three and adds a superscripted "+";
  1695. % it also adds such a "+" if the last of multiple authors is "others").
  1696. % If there is only one name, and its von and Last parts combined have just
  1697. % a single name-token ("Knuth" has a single token, "Brinch Hansen" has two),
  1698. % we take the first three letters of the last name.  The boolean
  1699. % et.al.char.used tells whether we've used a superscripted "+", so that we
  1700. % know whether to include a LaTeX macro for it.
  1701. %
  1702. % format.lab.names(s) ==
  1703. %  BEGIN
  1704. %    numnames := num.names$(s)
  1705. %    if numnames > 1 then
  1706. %        if numnames > 4 then
  1707. %        namesleft := 3
  1708. %        else
  1709. %        namesleft := numnames
  1710. %        nameptr := 1
  1711. %        nameresult := ""
  1712. %        while namesleft > 0
  1713. %          do
  1714. %        if (name_ptr = numnames) and
  1715. %             format.name$(s, nameptr, "{ff }{vv }{ll}{ jj}") = "others"
  1716. %           then nameresult := nameresult * "{\etalchar{+}}"
  1717. %            et.al.char.used := true
  1718. %           else nameresult := nameresult *
  1719. %                format.name$(s, nameptr, "{v{}}{l{}}")
  1720. %        nameptr := nameptr + 1
  1721. %        namesleft := namesleft - 1
  1722. %          od
  1723. %        if numnames > 4 then
  1724. %        nameresult := nameresult * "{\etalchar{+}}"
  1725. %        et.al.char.used := true
  1726. %    else
  1727. %        t := format.name$(s, 1, "{v{}}{l{}}")
  1728. %        if text.length$(t) < 2 then    % there's just one name-token
  1729. %        nameresult := text.prefix$(format.name$(s,1,"{ll}"),3)
  1730. %        else
  1731. %        nameresult := t
  1732. %        fi
  1733. %    fi
  1734. %    return nameresult
  1735. %  END
  1736. %
  1737. % Exactly what fields we look at in constructing the primary part of the label
  1738. % depends on the entry type; this selectivity (as opposed to, say, always
  1739. % looking at author, then editor, then key) helps ensure that "ignored" fields,
  1740. % as described in the LaTeX book, really are ignored.  Note that MISC is part
  1741. % of the deepest `else' clause in the nested part of calc.label; thus, any
  1742. % unrecognized entry type in the database is handled correctly.
  1743. %
  1744. % There is one auxiliary function for each of the four different sequences of
  1745. % fields we use.  The first of these functions looks at the author field, and
  1746. % then, if necessary, the key field.  The other three functions, which might
  1747. % look at two fields and the key field, are similar, except that the key field
  1748. % takes precedence over the organization field (for labels---not for sorting).
  1749. %
  1750. % The calc.label function calculates the preliminary label of an entry, which
  1751. % is formed by taking three letters of information from the author or editor or
  1752. % key or organization field (depending on the entry type and on what's empty,
  1753. % but ignoring a leading "The " in the organization), and appending the last
  1754. % two characters (digits) of the year. It is an error if the appropriate fields
  1755. % among author, editor, organization, and key are missing, and we use
  1756. % the first three letters of the cite$ in desperation when this happens.
  1757. % The resulting label has the year part, but not the name part, purify$ed
  1758. % (purify$ing the year allows some sorting shenanigans by the user).
  1759. %
  1760. % This function also calculates the version of the label to be used in sorting.
  1761. %
  1762. % The final label may need a trailing 'a', 'b', etc., to distinguish it from
  1763. % otherwise identical labels, but we can't calculated those "extra.label"s
  1764. % until after sorting.
  1765. %
  1766. % calc.label ==
  1767. %  BEGIN
  1768. %    if type$ = "book" or "inbook" then
  1769. %        author.editor.key.label
  1770. %    else if type$ = "proceedings" then
  1771. %        editor.key.organization.label
  1772. %    else if type$ = "manual" then
  1773. %        author.key.organization.label
  1774. %    else
  1775. %        author.key.label
  1776. %    fi fi fi
  1777. %    label := label * substring$(purify$(field.or.null(year)), -1, 2)
  1778. %        % assuming we will also sort, we calculate a sort.label
  1779. %    sort.label := sortify(label), but use the last four, not two, digits
  1780. %  END
  1781. INTEGERS { et.al.char.used }
  1782. FUNCTION {initialize.et.al.char.used}
  1783. { #0 'et.al.char.used :=
  1784. }
  1785. EXECUTE {initialize.et.al.char.used}
  1786. FUNCTION {format.lab.names}
  1787. { 's :=
  1788.   s num.names$ 'numnames :=
  1789.   numnames #1 >
  1790.     { numnames #2 >
  1791.        { s #1 "{vv }{ll}" format.name$ " et~al." * }
  1792.        { s #1 "{vv }{ll}" format.name$
  1793.          s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  1794.             { " et~al." * }
  1795.             { " and " * s #2 "{vv }{ll}" format.name$ * }
  1796.          if$
  1797.        }
  1798.       if$
  1799.     }
  1800.     { s #1 "{vv }{ll}" format.name$ }
  1801.   if$
  1802. }
  1803. FUNCTION {author.key.label}
  1804. { author empty$
  1805.     { key empty$
  1806.     { cite$ #1 #3 substring$ }
  1807.     { key #3 text.prefix$ }
  1808.       if$
  1809.     }
  1810.     { author format.lab.names }
  1811.   if$
  1812. }
  1813. FUNCTION {author.editor.key.label}
  1814. { author empty$
  1815.     { editor empty$
  1816.     { key empty$
  1817.         { cite$ #1 #3 substring$ }
  1818.         { key #3 text.prefix$ }
  1819.       if$
  1820.     }
  1821.     { editor format.lab.names }
  1822.       if$
  1823.     }
  1824.     { author format.lab.names }
  1825.   if$
  1826. }
  1827. FUNCTION {author.key.organization.label}
  1828. { author empty$
  1829.     { key empty$
  1830.     { organization empty$
  1831.         { cite$ #1 #3 substring$ }
  1832.         { "The " #4 organization chop.word #9 text.prefix$ }
  1833.       if$
  1834.     }
  1835.     { key #3 text.prefix$ }
  1836.       if$
  1837.     }
  1838.     { author format.lab.names }
  1839.   if$
  1840. }
  1841. FUNCTION {editor.key.organization.label}
  1842. { editor empty$
  1843.     { key empty$
  1844.     { organization empty$
  1845.         { cite$ #1 #3 substring$ }
  1846.         { "The " #4 organization chop.word #9 text.prefix$ }
  1847.       if$
  1848.     }
  1849.     { key #3 text.prefix$ }
  1850.       if$
  1851.     }
  1852.     { editor format.lab.names }
  1853.   if$
  1854. }
  1855. FUNCTION {calc.label}
  1856. { type$ "book" =
  1857.   type$ "inbook" =
  1858.   or
  1859.     'author.editor.key.label
  1860.     { type$ "proceedings" =
  1861.     'editor.key.organization.label
  1862.     { type$ "manual" =
  1863.         'author.key.organization.label
  1864.         'author.key.label
  1865.       if$
  1866.     }
  1867.       if$
  1868.     }
  1869.   if$
  1870.   duplicate$
  1871.   " " * year field.or.null purify$ #-1 #4 substring$
  1872.   *
  1873.   'label :=
  1874.   year field.or.null purify$ #-1 #4 substring$
  1875.   *
  1876.   sortify 'sort.label :=
  1877. }
  1878. % It doesn't seem like a particularly good idea to use an order-of-citation
  1879. % reference list when using alphabetic labels, but we need to have a
  1880. % special pass to calculate labels when this happens.
  1881. % When sorting, we compute the sortkey by executing "presort" on each entry.
  1882. % The presort key contains a number of "sortify"ed strings, concatenated
  1883. % with multiple blanks between them.  This makes things like "brinch  per"
  1884. % come before "brinch hansen  per".
  1885. %
  1886. % The fields used here are: the sort.label for alphabetic labels (as set by
  1887. % calc.label), followed by the author names (or editor names or organization
  1888. % (with a leading "The " removed) or key field, depending on entry type and on
  1889. % what's empty), followed by year, followed by the first bit of the title
  1890. % (chopping off a leading "The ", "A ", or "An ").
  1891. % Names are formatted: Von Last First Junior.
  1892. % The names within a part will be separated by a single blank
  1893. % (such as "brinch hansen"), two will separate the name parts themselves
  1894. % (except the von and last), three will separate the names,
  1895. % four will separate the names from year (and from label, if alphabetic),
  1896. % and four will separate year from title.
  1897. %
  1898. % The sort.format.names function takes an argument that should be in
  1899. % BibTeX name format, and returns a string containing "   "-separated
  1900. % names in the format described above.  The function is almost the same
  1901. % as format.names.
  1902. FUNCTION {sort.format.names}
  1903. { 's :=
  1904.   #1 'nameptr :=
  1905.   ""
  1906.   s num.names$ 'numnames :=
  1907.   numnames 'namesleft :=
  1908.     { namesleft #0 > }
  1909.     { nameptr #1 >
  1910.     { "   " * }
  1911.     'skip$
  1912.       if$                        % apalike uses initials
  1913.       s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't := % <= here
  1914.       nameptr numnames = t "others" = and
  1915.     { "et al" * }
  1916.     { t sortify * }
  1917.       if$
  1918.       nameptr #1 + 'nameptr :=
  1919.       namesleft #1 - 'namesleft :=
  1920.     }
  1921.   while$
  1922. }
  1923. % The sort.format.title function returns the argument,
  1924. % but first any leading "A "'s, "An "'s, or "The "'s are removed.
  1925. % The chop.word function uses s, so we need another string variable, t
  1926. FUNCTION {sort.format.title}
  1927. { 't :=
  1928.   "A " #2
  1929.     "An " #3
  1930.       "The " #4 t chop.word
  1931.     chop.word
  1932.   chop.word
  1933.   sortify
  1934.   #1 global.max$ substring$
  1935. }
  1936. % The auxiliary functions here, for the presort function, are analogous to
  1937. % the ones for calc.label; the same comments apply, except that the
  1938. % organization field takes precedence here over the key field.  For sorting
  1939. % purposes, we still remove a leading "The " from the organization field.
  1940. FUNCTION {author.sort}
  1941. { author empty$
  1942.     { key empty$
  1943.     { "to sort, need author or key in " cite$ * warning$
  1944.       ""
  1945.     }
  1946.     { key sortify }
  1947.       if$
  1948.     }
  1949.     { author sort.format.names }
  1950.   if$
  1951. }
  1952. FUNCTION {author.editor.sort}
  1953. { author empty$
  1954.     { editor empty$
  1955.     { key empty$
  1956.         { "to sort, need author, editor, or key in " cite$ * warning$
  1957.           ""
  1958.         }
  1959.         { key sortify }
  1960.       if$
  1961.     }
  1962.     { editor sort.format.names }
  1963.       if$
  1964.     }
  1965.     { author sort.format.names }
  1966.   if$
  1967. }
  1968. FUNCTION {author.organization.sort}
  1969. { author empty$
  1970.     { organization empty$
  1971.     { key empty$
  1972.         { "to sort, need author, organization, or key in " cite$ * warning$
  1973.           ""
  1974.         }
  1975.         { key sortify }
  1976.       if$
  1977.     }
  1978.     { "The " #4 organization chop.word sortify }
  1979.       if$
  1980.     }
  1981.     { author sort.format.names }
  1982.   if$
  1983. }
  1984. FUNCTION {editor.organization.sort}
  1985. { editor empty$
  1986.     { organization empty$
  1987.     { key empty$
  1988.         { "to sort, need editor, organization, or key in " cite$ * warning$
  1989.           ""
  1990.         }
  1991.         { key sortify }
  1992.       if$
  1993.     }
  1994.     { "The " #4 organization chop.word sortify }
  1995.       if$
  1996.     }
  1997.     { editor sort.format.names }
  1998.   if$
  1999. }
  2000. % There is a limit, entry.max$, on the length of an entry string variable
  2001. % (which is what its sort.key$ is), so we take at most that many characters
  2002. % of the constructed key, and hope there aren't many references that match
  2003. % to that many characters!
  2004. FUNCTION {presort}
  2005. { calc.label
  2006.   sort.label
  2007.   "    "
  2008.   *
  2009.   type$ "book" =
  2010.   type$ "inbook" =
  2011.   or
  2012.     'author.editor.sort
  2013.     { type$ "proceedings" =
  2014.     'editor.organization.sort
  2015.     { type$ "manual" =
  2016.         'author.organization.sort
  2017.         'author.sort
  2018.       if$
  2019.     }
  2020.       if$
  2021.     }
  2022.   if$
  2023.   *
  2024.   "    "
  2025.   *
  2026.   year field.or.null sortify
  2027.   *
  2028.   "    "
  2029.   *
  2030.   title field.or.null
  2031.   sort.format.title
  2032.   *
  2033.   #1 entry.max$ substring$
  2034.   'sort.key$ :=
  2035. }
  2036. ITERATE {presort}
  2037. % And now we can sort
  2038. SORT
  2039. % This long comment applies only to alphabetic labels, when sorted
  2040. %
  2041. % Now comes the final computation for alphabetic labels, putting in the 'a's
  2042. % and 'b's and so forth if required.  This involves two passes: a forward
  2043. % pass to put in the 'b's, 'c's and so on, and a backwards pass
  2044. % to put in the 'a's (we don't want to put in 'a's unless we know there
  2045. % are 'b's).
  2046. % We have to keep track of the longest (in width$ terms) label, for use
  2047. % by the "thebibliography" environment.
  2048. %
  2049. % VAR: longest.label, last.sort.label, next.extra: string
  2050. %      longest.label.width, last.extra.num: integer
  2051. %
  2052. % initialize.longest.label ==
  2053. %  BEGIN
  2054. %    longest.label := ""
  2055. %    last.sort.label := int.to.chr$(0)
  2056. %    next.extra := ""
  2057. %    longest.label.width := 0
  2058. %    last.extra.num := 0
  2059. %  END
  2060. %
  2061. % forward.pass ==
  2062. %  BEGIN
  2063. %    if last.sort.label = sort.label then
  2064. %        last.extra.num := last.extra.num + 1
  2065. %        extra.label := int.to.chr$(last.extra.num)
  2066. %    else
  2067. %        last.extra.num := chr.to.int$("a")
  2068. %        extra.label := ""
  2069. %        last.sort.label := sort.label
  2070. %    fi
  2071. %  END
  2072. %
  2073. % reverse.pass ==
  2074. %  BEGIN
  2075. %    if next.extra = "b" then
  2076. %        extra.label := "a"
  2077. %    fi
  2078. %    label := label * extra.label
  2079. %    if width$(label) > longest.label.width then
  2080. %        longest.label := label
  2081. %        longest.label.width := width$(label)
  2082. %    fi
  2083. %    next.extra := extra.label
  2084. %  END
  2085. STRINGS { longest.label last.sort.label next.extra }
  2086. INTEGERS { longest.label.width last.extra.num }
  2087. FUNCTION {initialize.longest.label}
  2088. { "" 'longest.label :=
  2089.   #0 int.to.chr$ 'last.sort.label :=
  2090.   "" 'next.extra :=
  2091.   #0 'longest.label.width :=
  2092.   #0 'last.extra.num :=
  2093. }
  2094. FUNCTION {forward.pass}
  2095. { last.sort.label sort.label =
  2096.     { last.extra.num #1 + 'last.extra.num :=
  2097.       last.extra.num int.to.chr$ 'extra.label :=
  2098.     }
  2099.     { "a" chr.to.int$ 'last.extra.num :=
  2100.       "" 'extra.label :=
  2101.       sort.label 'last.sort.label :=
  2102.     }
  2103.   if$
  2104. }
  2105. FUNCTION {reverse.pass}
  2106. { next.extra "b" =
  2107.     { "a" 'extra.label := }
  2108.     'skip$
  2109.   if$
  2110.   label extra.label * 'label :=
  2111.   label width$ longest.label.width >
  2112.     { label 'longest.label :=
  2113.       label width$ 'longest.label.width :=
  2114.     }
  2115.     'skip$
  2116.   if$
  2117.   extra.label 'next.extra :=
  2118. }
  2119. EXECUTE {initialize.longest.label}
  2120. ITERATE {forward.pass}
  2121. REVERSE {reverse.pass}
  2122. % Now we're ready to start writing the .BBL file.
  2123. % We begin, if necessary, with a LaTeX macro for unnamed names in an alphabetic
  2124. % label; next comes stuff from the `preamble' command in the database files.
  2125. % Then we give an incantation containing the command
  2126. %     \begin{thebibliography}{...}
  2127. % where the `...' is the longest label.
  2128. %
  2129. % We also call init.state.consts, for use by the output routines.
  2130. FUNCTION {begin.bib}
  2131. { et.al.char.used
  2132.     { "\newcommand{\etalchar}[1]{$^{#1}$}" write$ newline$ }
  2133.     'skip$
  2134.   if$
  2135.   preamble$ empty$
  2136.     'skip$
  2137.     { preamble$ write$ newline$ }
  2138.   if$
  2139.   "\begin{thebibliography}{"  longest.label  * "}" * write$ newline$
  2140. }
  2141. EXECUTE {begin.bib}
  2142. EXECUTE {init.state.consts}
  2143. % Now we produce the output for all the entries
  2144. ITERATE {call.type$}
  2145. % Finally, we finish up by writing the `\end{thebibliography}' command.
  2146. FUNCTION {end.bib}
  2147. { newline$
  2148.   "\end{thebibliography}" write$ newline$
  2149. }
  2150. EXECUTE {end.bib}
  2151.